<?php
namespace App\Models;

class Pay extends BaseModel
{


    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 按条件查询单条数据
     */
    public function getOne(array $where, $fields = '*')
    {
        return $this->multiSelect($fields)->multiWhere($where)->first();
    }

    /**
     * 按条件查询全部数据,根据配置显示条数显示
     */
    public function getList(array $where = [], $fields = '*', $order = '', $pageSize = '')
    {
        if ($pageSize) {
            return $this->multiSelect($fields)->multiWhere($where)->multiOrder($order)->paginate($pageSize);
        } else {
            return $this->multiSelect($fields)->multiWhere($where)->multiOrder($order)->get();
        }

    }

    /**
     * 根据条件删除数据
     */
    public function del(array $where)
    {
        return $this->multiWhere($where)->delete();
    }

    /**
     *插入数据
     */
    public function add($data)
    {
//        dd($data);
        return $this->insertGetId($data);
    }

    /**
     *更新数据
     */
    public function up($where, $data)
    {
        return $this->multiWhere($where)->update($data);
    }

    /**
     * 获取和
     */
    public function getSum($where, $field)
    {
        return $this->multiWhere($where)->sum($field);
    }

    /**
     * 字段递加
     */
    public function inc($where, $field, $n)
    {
        return $this->multiWhere($where)->increment($field, $n);
    }

    /**
     * 微信前支付检测
     */
    public function his_reg_pay_check($param){
         $data['vac01'] = $param['reffer_id'];
         $data['amount'] = $param['register_price'];
         return $data;
    }

    public function his_wx_online_pay_check($amount,$id){
        $data['amount'] = $amount;
        $data['paylist'] = $id;
        return $data;
    }

    /**
     * 挂号支付
     * @param $vac01  int     挂号id
     * @param $payno string  微信支付单号
     * @param $payamount numeric（12，2） 支付金额
     * @param $paytime string  付款时间 yyyy-mm-dd hh:nn:ss
     * return
     * Result 1成功0失败
     * Errmsg 失败信息/错误原因
     */
    public function his_reg_pay($aid){
        $appointment = new Appointment();
        $appointmentInfo = $appointment->getAppPointmentById($aid);
        $data['vac01'] = $appointmentInfo['reffer_id'];
        $data['payno'] = $appointmentInfo['order_no'];
        $data['payamount'] = $appointmentInfo['register_price'];
        $data['paytime'] = date('Y-m-d H:i:s',time());
        return $data;
    }

    /**
     * 挂号支付（使用折扣券或者代金券，不能同时使用）
     * @param $vac01  int     挂号id
     * @param $payno string  微信支付单号
     * @param $totalamount numeric（18，2） 总金额
     * @param $payamount numeric（18，2） 实付金额
     * @param $paytime string  付款时间 yyyy-mm-dd hh:nn:ss
     * @param $memo string  备注
     * return
     * Result 0成功，大于0失败
     * Errmsg 失败信息/错误原因
     */
    public function his_reg_pay_by_coupon($aid)
    {
        //$vac01,$payno,$totalamount,$payamount,$paytime,$memo
        $appointment = new Appointment();
        $appointmentInfo = $appointment->getAppPointmentById($aid);
        $data['vac01'] = $appointmentInfo['reffer_id'];
        $data['payno'] = $appointmentInfo['order_no'];
        $data['totalamount'] = $appointmentInfo['register_price'];
        $data['payamount'] = $appointmentInfo['register_price'];
        $data['paytime'] = date('Y-m-d H:i:s',time());
        $data['memo'] = '线上微信支付';
        return $data;
    }
}